﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using QuanLyGiaoVuDAL.DTO;
using AutoMapper;

namespace QuanLyGiaoVuUI.Models.ChiTietThongBao
{
    public class ChiTietThongBaoViewModel
    {
        public Guid MaChiTietThongBao { get; set; }
        public Guid MaThongBao { get; set; }
        public Guid MaNguoiNhan { get; set; }
        public int DaXem { get; set; }

        public int SoLuongChuaXem { get; set; }
        public ThongBaoDTO ThongBao { get; set; }

        public ChiTietThongBaoDTO ToChiTietThongBaoDTO()
        {
            Mapper.CreateMap(typeof(ChiTietThongBaoViewModel), typeof(ChiTietThongBaoDTO));
            var chiTietThongBaoDTO = new ChiTietThongBaoDTO();
            Mapper.Map(this, chiTietThongBaoDTO);
            return chiTietThongBaoDTO;
        }

        public static ChiTietThongBaoViewModel FromChiTietThongBaoDTO(ChiTietThongBaoDTO chiTietThongBaoDTO)
        {
            Mapper.CreateMap(typeof(ChiTietThongBaoDTO), typeof(ChiTietThongBaoViewModel));
            var chiTietThongBaoViewModel = new ChiTietThongBaoViewModel();
            Mapper.Map(chiTietThongBaoDTO, chiTietThongBaoViewModel);
            return chiTietThongBaoViewModel;
        }
        public static IEnumerable<ChiTietThongBaoViewModel> FromChiTietThongBaoDTOList(IEnumerable<ChiTietThongBaoDTO> chiTietThongBaoDTOList)
        {
            //if (chiTietThongBaoDTOList == null)
            //{
            //    return null;
            //}
            List<ChiTietThongBaoViewModel> chiTietThongBaoList = new List<ChiTietThongBaoViewModel>();
            foreach (ChiTietThongBaoDTO chiTietThongBaoDTO in chiTietThongBaoDTOList)
            {
                chiTietThongBaoList.Add(ChiTietThongBaoViewModel.FromChiTietThongBaoDTO(chiTietThongBaoDTO));
            }
            return chiTietThongBaoList.AsEnumerable();
        }
    }
}